home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_netUpdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  9.0 KB  |  345 lines

  1. /*****************************************************************************
  2.   FILE           : ui_netUpdate.c
  3.   SHORTNAME      : netUpdat.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        :
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Tilman Sommer
  10.   DATE           : 1.2.1990
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)ui_netUpdate.c    1.11 3/2/94
  14.   SCCS VERSION   : 1.11
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <memory.h>
  24.  
  25. #include "ui.h"
  26. #include "kr_ui.h"
  27. #include "ui_netGraph.h"
  28. #include "ui_xGraphic.h" 
  29. #include "ui_xWidgets.h"    
  30. /* ui_xGetDimensions */
  31. #include "ui_display.h"
  32. #include "ui_utilP.h"
  33. #include "ui_displwght.h"
  34. #include "ui_mainP.h"
  35. #include "ui_selection.h"
  36. #include "ui_colEdit.h"
  37.  
  38. #include "glob_typ.h"
  39. #include "d3_global.h"         
  40. #include "d3_draw.h"
  41. #include "d3_main.h"
  42. #include "ui_color.h"
  43.  
  44. #include "ui_netUpdate.ph"
  45.  
  46.  
  47. /*****************************************************************************
  48.   FUNCTION : ui_net_drawLink
  49.  
  50.   PURPOSE  : draw a link
  51.   RETURNS  : void
  52.   NOTES    : 
  53.  
  54.   UPDATE   :
  55. *****************************************************************************/
  56.  
  57. void ui_net_drawLink (struct Ui_DisplayType *displayPtr, FlagType scope, 
  58.     int sourceNo, int targetNo, FlintType weight, Bool operation)
  59.  
  60. {
  61.     if (scope == UI_GLOBAL) {
  62.     struct Ui_DisplayType  *dPtr;
  63.     dPtr = ui_displ_listPtr;
  64.     while (dPtr != NULL) {
  65.         /* all the same subnet number ? */
  66.         if ((dPtr->subNetNo == krui_getUnitSubnetNo(sourceNo)) AND 
  67.         (krui_getUnitSubnetNo(sourceNo) == krui_getUnitSubnetNo(targetNo)))
  68.         if ((NOT dPtr->frozen) AND ui_utilIsSet(dPtr->flags,1)) /*!*/
  69.             ui_drawLink(dPtr, sourceNo, targetNo, weight, operation);
  70.         dPtr = dPtr->nextPtr;
  71.     }
  72.     } else
  73.     /* all the same subnet number ? */
  74.     if ((displayPtr != NULL) AND
  75.             (displayPtr->subNetNo == krui_getUnitSubnetNo(sourceNo)) AND 
  76.         (krui_getUnitSubnetNo(sourceNo) == krui_getUnitSubnetNo(targetNo)))
  77.            ui_drawLink(displayPtr, sourceNo, targetNo, weight, operation);
  78. }
  79.  
  80.  
  81. /*****************************************************************************
  82.   FUNCTION : ui_net_drawUnit
  83.  
  84.   PURPOSE  : draw a unit
  85.   RETURNS  : void
  86.   NOTES    : 
  87.  
  88.   UPDATE   :
  89. *****************************************************************************/
  90.  
  91. void ui_net_drawUnit (struct Ui_DisplayType *displayPtr, FlagType scope, 
  92.     int unitNo, Bool operation)
  93.  
  94. {
  95.     if (scope == UI_GLOBAL) {
  96.     struct Ui_DisplayType *dPtr;
  97.     dPtr = ui_displ_listPtr;
  98.     while (dPtr != NULL) {
  99.         /* all same subnet number like display? */
  100.         if ((dPtr->subNetNo == krui_getUnitSubnetNo(unitNo))) 
  101.         if ((NOT dPtr->frozen) AND ui_utilIsSet(dPtr->flags,1)) /*!*/
  102.             ui_drawUnit(dPtr, unitNo, operation);
  103.         dPtr = dPtr->nextPtr;
  104.     }
  105.     } else
  106.     /* all same subnet number like display? */
  107.     if ((displayPtr->subNetNo == krui_getUnitSubnetNo(unitNo)))
  108.         ui_drawUnit(displayPtr, unitNo, operation);
  109. }
  110.  
  111.  
  112. /*****************************************************************************
  113.   FUNCTION : ui_net_drawAllLinksToUnit
  114.  
  115.   PURPOSE  : This routine draws all links of the specified unit.
  116.   RETURNS  : update of the graphic window  
  117.   NOTES    : operation can be either UI_ERASE or UI_DRAW
  118.  
  119.   UPDATE   :
  120. *****************************************************************************/
  121.  
  122. void ui_net_drawAllLinksToUnit (struct Ui_DisplayType *displayPtr, 
  123.     FlagType scope, int unitNo, Bool operation)
  124.  
  125. {
  126.     struct Ui_DisplayType  *dPtr;
  127.     Bool             successful;
  128.     FlintType        weight;
  129.     int              predUnit;
  130.     Bool             blocked;
  131.  
  132.     blocked = TRUE;
  133.     if (scope == UI_GLOBAL) {
  134.     dPtr = ui_displ_listPtr;
  135.     while (dPtr != NULL) {
  136.            if ((dPtr->setup).showLinkFlg)
  137.               blocked = FALSE;
  138.            dPtr = dPtr->nextPtr;
  139.     }
  140.     } else
  141.         blocked = NOT ((displayPtr->setup).showLinkFlg);
  142.  
  143.     if (blocked)
  144.         return;
  145.  
  146.     (void) krui_setCurrentUnit(unitNo);
  147.  
  148.     if (krui_getUnitInputType(unitNo) == SITES) {
  149.     for (successful = krui_setFirstSite();
  150.          successful; successful = krui_setNextSite()) {
  151.         for(predUnit = krui_getFirstPredUnit(&weight);
  152.         predUnit > 0;
  153.         predUnit = krui_getNextPredUnit(&weight)) {
  154.         ui_net_drawLink(displayPtr, scope, predUnit, unitNo, 
  155.                 weight, operation);
  156.         }
  157.     }
  158.     } else /* direct links */
  159.       {
  160.     for(predUnit = krui_getFirstPredUnit(&weight);
  161.         predUnit > 0;
  162.         predUnit = krui_getNextPredUnit(&weight)) {
  163.         ui_net_drawLink(displayPtr, scope, predUnit, unitNo, 
  164.                 weight, operation);
  165.     }
  166.       }
  167. }
  168.  
  169.  
  170.  
  171.  
  172. /*****************************************************************************
  173.   FUNCTION : ui_net_drawAllLinksFromUnit
  174.  
  175.   PURPOSE  : This routine draws all links of the specified unit.
  176.   RETURNS  : update of the graphic window
  177.   NOTES    : operation can be either UI_ERASE or UI_DRAW
  178.  
  179.   UPDATE   :
  180. *****************************************************************************/
  181.  
  182. void ui_net_drawAllLinksFromUnit (struct Ui_DisplayType *displayPtr, 
  183.     FlagType scope, int unitNo, FlagType operation)
  184.  
  185. {
  186.     Bool               successful;
  187.     FlintType          weight;
  188.     int                targetNo;
  189.  
  190.     (void) krui_setCurrentUnit(unitNo);
  191.  
  192.     successful = 
  193.     ((targetNo = krui_getFirstSuccUnit(unitNo, &weight)) > 0);
  194.  
  195.     while (successful) {
  196.     ui_net_drawLink(displayPtr, scope, unitNo, targetNo, 
  197.             weight, operation);
  198.     successful = 
  199.         ((targetNo = krui_getNextSuccUnit(&weight)) > 0);
  200.     }
  201. }
  202.  
  203.  
  204. /*****************************************************************************
  205.   FUNCTION : ui_net_updateWhole
  206.  
  207.   PURPOSE  : draws all units or links, depending of the parameter (see below)
  208.   RETURNS  : update in the graphic window
  209.   NOTES    : whatToDraw:
  210.          UI_DRAW_UNITS
  211.          UI_DRAW_LINKS
  212.  
  213.   UPDATE   :
  214. *****************************************************************************/
  215.  
  216. void ui_net_updateWhole (struct Ui_DisplayType *displayPtr, FlagType scope, 
  217.     int whatToDraw, Bool erase)
  218.  
  219. {
  220.     Bool   successful;
  221.     int    unitNo;
  222.  
  223.     /*!*/
  224.     if (krui_getNoOfUnits() < 1)
  225.     return;
  226.  
  227.     successful = 
  228.     ((unitNo = krui_getFirstUnit()) > 0);
  229.  
  230.     if (successful) {
  231.     /* ui_can_setBusyCursor(); */
  232.     
  233.     while (successful) {
  234.         if (whatToDraw == UI_DRAW_LINKS)
  235.         ui_net_drawAllLinksToUnit(displayPtr, scope, unitNo, erase);
  236.         if (whatToDraw == UI_DRAW_UNITS)
  237.              ui_net_drawUnit(displayPtr, scope, unitNo, erase);
  238.         successful = 
  239.         ((unitNo = krui_getNextUnit()) > 0);
  240.     } /* end while */
  241.  
  242.     ui_printMessage("");    /* erase message */
  243.     /* ui_can_setNormalCursor(); */
  244.  
  245.     } else         
  246.     if (whatToDraw == UI_DRAW_UNITS) /* there are no units to draw ! */
  247.         ui_printMessage("The network is empty!");
  248.  
  249.     if (whatToDraw == UI_DRAW_UNITS) {
  250.         d3_drawNet ();
  251.     ui_displWeightsFromUpdate();
  252.     }
  253. }
  254.  
  255.  
  256. /*****************************************************************************
  257.   FUNCTION : ui_net_doClearWindow
  258.  
  259.   PURPOSE  :
  260.   RETURNS  : void
  261.   NOTES    :
  262.  
  263.   UPDATE   : 1.2.1990
  264. ******************************************************************************/
  265.  
  266. static void  ui_net_doClearWindow (struct Ui_DisplayType *displayPtr)
  267.  
  268. {
  269.     struct PosType pixPos1;
  270.     struct PosType pixPos2;
  271.      
  272.     pixPos1.x = 0;
  273.     pixPos1.y = 0;
  274.  
  275.     ui_xGetDimensions(displayPtr->widget, 
  276.               &(displayPtr->width), &(displayPtr->height));
  277.     
  278.     displayPtr->unitsInX = displayPtr->width  / displayPtr->gridSize;
  279.     displayPtr->unitsInY = displayPtr->height / displayPtr->gridSize;
  280.  
  281.     pixPos2.x = displayPtr->width  - 1;
  282.     pixPos2.y = displayPtr->height - 1;
  283.     
  284.     XSetFunction(ui_display, ui_gc, GXcopy);
  285.     XSetForeground(ui_display, ui_gc, ui_backgroundColor);
  286.     
  287.     /* clear canvas */
  288.     ui_xDeleteRect(ui_display, displayPtr->drawable, 
  289.            ui_gc, pixPos1, pixPos2); 
  290. }
  291.  
  292.  
  293. /*****************************************************************************
  294.   FUNCTION : ui_net_clearWindow
  295.  
  296.   PURPOSE  : clear specified window
  297.   RETURNS  : void
  298.   NOTES    : 
  299.  
  300.   UPDATE   :
  301. *****************************************************************************/
  302.  
  303. static void ui_net_clearWindow (struct Ui_DisplayType *displayPtr, 
  304.     FlagType scope)
  305.  
  306. {
  307.     if (scope == UI_GLOBAL) {
  308.     struct Ui_DisplayType  *dPtr;
  309.  
  310.     dPtr = ui_displ_listPtr;
  311.     while (dPtr != NULL) {
  312.         if (NOT dPtr->frozen) ui_net_doClearWindow(dPtr);
  313.         dPtr = dPtr->nextPtr;
  314.     }        
  315.     } else 
  316.     ui_net_doClearWindow(displayPtr);
  317. }
  318.  
  319.  
  320. /*****************************************************************************
  321.   FUNCTION : ui_net_completeRefresh
  322.  
  323.   PURPOSE  : new drawing of the entire network
  324.   RETURNS  : update of the graphik window
  325.   NOTES    : To draw the links takes a long time, if the network is big.
  326.  
  327.   UPDATE   :
  328. *****************************************************************************/
  329.  
  330. void ui_net_completeRefresh (struct Ui_DisplayType *displayPtr, FlagType scope)
  331.  
  332. {
  333.     ui_net_clearWindow(displayPtr, scope);
  334.     ui_net_updateWhole(displayPtr, scope, UI_DRAW_LINKS, UI_DRAW);
  335.     ui_net_updateWhole(displayPtr, scope, UI_DRAW_UNITS, UI_DRAW);
  336.     ui_sel_reshowItems(displayPtr, scope);  /* redraw marker of selected items */
  337. }
  338.  
  339.  
  340.  
  341.  
  342.  
  343. /* end of file */
  344. /* lines: 420 */
  345.